﻿using agsXMPP.Xml.Dom;

namespace Lapd.Common.CustomStanzas
{

    public class Sdds : Element
    {
        #region Samples stanzas

        /*
         * JOIN TO GROUP
         * ----
            <sdds xmlns="sddsopenfire"> 
		        <join group="groupName">
			    </join>
		    </sdds>	
        */

        /*
         * WRITE ON TOPIC
         * --------------
            <sdds xmlns="sddsopenfire">
	            <write instancename="SampleTopic">
		            <samplefield datatype="long" value="1">
		            </samplefield>
		            <samplefield datatype="long" value="1">
		            </samplefield>
		            <samplefield datatype="string" value="temperature">
		            </samplefield>
		            <samplefield datatype="string" value="20.0">
		            </samplefield>
	            </write>
            </sdds>
         */

        /*
         * NEW
         * ---
            <sdds xmlns="sddsopenfire">
		        <new datatype="MoteSample.SampleTopic" instancename="SampleTopic">
		        </new>
	        </sdds>
         */

        /*
         * LISTEN
         * ------
            <sdds xmlns="sddsopenfire">
		        <listen instancename="SampleTopic">
		        </listen>
	        </sdds>
         */

        #endregion

        public Sdds()
        {
            TagName = ServiceDdsConstants.SDDS_TAG_NAME;
            Namespace = ServiceDdsConstants.SDDS_OPENFIRE_NAMESPACE;
        }

        public Sdds(Join join) : this()
        {
            Join = join;
        }

        public Sdds(Write write)
            : this()
        {
            Write = write;
        }

        public Sdds(New newStanza)
            : this()
        {
            New = newStanza;
        }

        public Sdds(Listen listen)
            : this()
        {
            Listen = listen;
        }

        public Join Join
        {
            get
            {
                return SelectSingleElement(typeof(Join)) as Join;
            }
            set
            {
                if (HasTag(typeof(Join)))
                    RemoveTag(typeof(Join));

                if (value != null)
                    AddChild(value);
            }
        }

        public Write Write
        {
            get
            {
                return SelectSingleElement(typeof(Write)) as Write;
            }
            set
            {
                if (HasTag(typeof(Write)))
                    RemoveTag(typeof(Write));

                if (value != null)
                    AddChild(value);
            }
        }

        public New New
        {
            get
            {
                return SelectSingleElement(typeof(New)) as New;
            }
            set
            {
                if (HasTag(typeof(New)))
                    RemoveTag(typeof(New));

                if (value != null)
                    AddChild(value);
            }
        }

        public Listen Listen
        {
            get
            {
                return SelectSingleElement(typeof(Listen)) as Listen;
            }
            set
            {
                if (HasTag(typeof(Listen)))
                    RemoveTag(typeof(Listen));

                if (value != null)
                    AddChild(value);
            }
        }
    }
}